import {
  ModalForm,
  ProFormDatePicker,
  ProFormDigit,
  ProFormSelect,
  ProFormText,
  ProFormTextArea
} from '@ant-design/pro-components';
import {Form} from 'antd';
import React from 'react';

interface CoachFormProps {
  trigger?: React.ReactNode;
  initialValues?: API.ICoach;
  onFinish: (values: API.ICoach) => Promise<boolean>;
  title?: string;
  onOpenChange?: (open: boolean) => void;
}

const CoachForm: React.FC<CoachFormProps> = ({
                                               trigger,
                                               initialValues,
                                               onFinish,
                                               title,
                                               onOpenChange
                                             }) => {
  const [form] = Form.useForm<API.ICoach>();

  return (
    <ModalForm<API.ICoach>
      form={form}
      title={title || (initialValues ? '编辑教练信息' : '新增教练')}
      trigger={trigger as any}
      initialValues={initialValues}
      onFinish={onFinish}
      onOpenChange={(open) => {
        if (!open) form.resetFields();
        onOpenChange?.(open);
      }}
      modalProps={{
        destroyOnClose: true,
        maskClosable: false,
        width: 800 // 加宽模态框
      }}
      grid
      rowProps={{gutter: 24}}
    >
      {/* 第一行 */}
      <ProFormText
        name="name"
        label="教练姓名"
        colProps={{span: 12}}
        rules={[{required: true}]}
        placeholder="请输入教练姓名"
      />
      <ProFormSelect
        name="gender"
        label="性别"
        colProps={{span: 12}}
        options={[
          {label: '男', value: "0"},
          {label: '女', value: "1"}
        ]}
      />

      {/* 第二行 */}
      <ProFormText
        name="idCard"
        label="身份证号"
        colProps={{span: 12}}
        rules={[
          {required: true},
          {pattern: /^\d{17}[\dXx]$/, message: '身份证格式错误'}
        ]}
      />
      <ProFormText
        name="phone"
        label="联系电话"
        colProps={{span: 12}}
        rules={[
          {required: true},
          {pattern: /^1[3-9]\d{9}$/, message: '手机号格式错误'}
        ]}
      />

      {/* 第三行 */}
      <ProFormText
        name="address"
        label="联系地址"
        colProps={{span: 12}}
        rules={[{required: true}]}
      />
      <ProFormDatePicker
        name="hireDate"
        label="入职日期"
        colProps={{span: 12}}
        fieldProps={{
          format: 'YYYY-MM-DD',
          style: {width: '100%'}
        }}
        rules={[{required: true, message: '入职日期不能为空'}]}
      />

      {/* 第四行 */}
      <ProFormText
        name="licenseNumber"
        label="教练证编号"
        colProps={{span: 12}}
        rules={[{required: true}]}
      />
      <ProFormSelect
        name="licenseType"
        label="教练证类型"
        colProps={{span: 12}}
        options={[
          {label: 'A1大型客车教练证', value: 'A1大型客车教练证'},
          {label: 'A2牵引车教练证', value: 'A2牵引车教练证'},
          {label: 'A3城市公交车教练证', value: 'A3城市公交车教练证'},
          {label: 'B1中型客车教练证', value: 'B1中型客车教练证'},
          {label: 'B2大型货车教练证', value: 'B2大型货车教练证'},
          {label: 'C1小型汽车教练证', value: 'C1小型汽车教练证'},
          {label: 'C2小型自动挡汽车教练证', value: 'C2小型自动挡汽车教练证'},
          {label: 'C3低速载货汽车教练证', value: 'C3低速载货汽车教练证'},
          {label: 'C4三轮汽车教练证', value: 'C4三轮汽车教练证'},
          {label: 'D普通三轮摩托车教练证', value: 'D普通三轮摩托车教练证'},
          {label: 'E普通二轮摩托车教练证', value: 'E普通二轮摩托车教练证'},
          {label: 'F轻便摩托车教练证', value: 'F轻便摩托车教练证'},
          {label: '特殊技能教练证（如防御性驾驶）', value: '特殊技能教练证'},
          {label: '理论教练员资格证', value: '理论教练员资格证'},
          {label: '道路运输从业资格培训教练证', value: '道路运输从业资格培训教练证'}
        ]}
      />

      {/* 第五行 */}
      <ProFormSelect
        name="status"
        label="状态"
        colProps={{span: 12}}
        options={[
          {label: '在职', value: "1"},
          {label: '休假', value: "2"},
          {label: '离职', value: "3"}
        ]}
      />
      <ProFormDigit
        name="teachingHours"
        label="教学时长(小时)"
        colProps={{span: 12}}
        min={0}
      />

      {/* 第六行（整行） */}
      <ProFormText
        name="specialty"
        label="教学专长"
        colProps={{span: 24}}
        placeholder="如：科目二教学、夜间驾驶等"
      />

      {/* 第七行（整行） */}
      <ProFormTextArea
        name="remark"
        label="备注"
        colProps={{span: 24}}
        fieldProps={{rows: 3}}
      />
    </ModalForm>
  );
};

export default CoachForm;
